package com.magnificent.atlantis.common.entity.messages;

import com.magnificent.commons.db.datasource.ObjectEntity;

import javax.persistence.*;
import java.util.Date;

/**
 * User: Babanin
 * Date: 04.05.2009
 * Time: 21:58:33
 */
@MappedSuperclass()
public abstract class ServerMessage extends ObjectEntity {

    protected Date sentDate;

    protected int userToId;
    protected int userFromId;

    protected ServerMessage() {
    }

    @Basic()
    @Column(name = "sentDate")
    public Date getSentDate() {
        return sentDate;
    }

    public void setSentDate(Date sentDate) {
        this.sentDate = sentDate;
    }

    @Basic()
    @Column(name = "userToId")
    public int getUserToId() {
        return userToId;
    }

    public void setUserToId(int userToId) {
        this.userToId = userToId;
    }

    @Basic()
    @Column(name = "userFromId")
    public int getUserFromId() {
        return userFromId;
    }

    public void setUserFromId(int userFromId) {
        this.userFromId = userFromId;
    }

    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        ServerMessage that = (ServerMessage) o;

        if (userFromId != that.userFromId) return false;
        if (userToId != that.userToId) return false;
        if (sentDate != null ? !sentDate.equals(that.sentDate) : that.sentDate != null) return false;

        return true;
    }

    public int hashCode() {
        int result;
        result = (sentDate != null ? sentDate.hashCode() : 0);
        result = 31 * result + userToId;
        result = 31 * result + userFromId;
        return result;
    }
}
